package com.liu.activiti.config;

import com.liu.activiti.service.ActivitiCoreService;
import com.liu.activiti.service.impl.ActivitiCoreServiceImpl;
import com.liu.activiti.utils.ActivitiTracingChart;
import lombok.extern.slf4j.Slf4j;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;

@Slf4j
//@Configuration
//@ConditionalOnClass(value = {ActivitiCoreService.class, ActivitiCoreServiceImpl.class, BaseActivitService.class, ActivitiTracingChart.class, ActivitiStart.class})
public class ActivitiConfigrure {

    @Bean
    @ConditionalOnMissingBean
    public ActivitiCoreService activitiCoreService(){
        return new ActivitiCoreServiceImpl();
    }

    @Bean
    @ConditionalOnMissingBean
    public ActivitiTracingChart activitiTracingChart(){
        return new ActivitiTracingChart();
    }

    @Bean
    @ConditionalOnMissingBean
    public ActivitiStart activitiStart(){
        return new ActivitiStart();
    }

    @Bean
    public SpringProcessEngineConfiguration springProcessEngineConfiguration(DataSource dataSource, PlatformTransactionManager platformTransactionManager){
        log.debug("Activiti引擎 配置初始化----------开始------------->");
        SpringProcessEngineConfiguration springProcessEngineConfiguration = new SpringProcessEngineConfiguration();
        //设置数据源
        springProcessEngineConfiguration.setDataSource(dataSource);
        //设置事务管理器
        springProcessEngineConfiguration.setTransactionManager(platformTransactionManager);
        //自动创建流程引擎表
        springProcessEngineConfiguration.setDatabaseSchemaUpdate("true");
        log.debug("Activiti引擎 配置初始化----------结束------------>");
        return springProcessEngineConfiguration;
    }
}

